package org.bt4girls.oauth.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

@RestController
public class TestController {
    @Autowired
    private DataSource dataSource;


    @RequestMapping(value = "/test")
    public String test(){
        return "success";
    }


    @RequestMapping(value = "/mysql")
    public String test2(){
        Connection connection = null;
        try {
            connection = dataSource.getConnection();
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery("select * from test");
            if(resultSet.next()){
                System.out.println(resultSet.getString("id"));
                System.out.println(resultSet.getString("msg"));
            }
            statement.close();
            connection.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return "success";
    }
}
